const { Schema } =require("mongoose")//引入mobgoose
let mongoose =require("./db")//导入暴露的db.js
//用户
let user =new Schema({//配置表子段
    uname:String,//用户名
    password:String,//密码
    chapter:{//章节
        type:mongoose.Types.ObjectId,
        res:"chapter"
    },
    collect:{//收藏
      type:mongoose.Types.ObjectId,
      res:"collect"
  }
})
//章节
let chapters=new Schema({
    chaptname:String,//章节名称
    sections:{//题
        type:mongoose.Types.ObjectId,
        res:"sections"
    }
})
//错题记录
let errsection=new Schema({
    question:{//题号-（题库question的_id
        type:mongoose.Types.ObjectId,
        res:"sections"
    },
    checka:String,//选择的项（ABCD）
    chapters:{//所属章节chapters的_id
        type:mongoose.Types.ObjectId,
        res:"chapters"
    }   
    })
//题库
let question=new Schema({
    topic:String,//题目
    types:{//题目类型（true单选false多选）
        type:Boolean,
        default:true
    },
    category:Number,//类别（错题分析用）如：0是mysql，1是Vue，2是React,3是Umi
    Answerpars:String,//答案
    parse:String//解析
})
let userModel =mongoose.model("user",user,"user")//创建用户表
let chaptersModel =mongoose.model("chapters",chapters,"chapters")//创建章节表
let questionModel =mongoose.model("question",question,"question")//创建题库表
let errsectionModel=mongoose.model("errsection",errsection,"errsection")//错题记录

// userModel.create({
//     uname:"admin",
//     password:"123456"
// })
module.exports={//暴露数据表
    userModel,chaptersModel,questionModel,errsectionModel
 }
